package com.lam.fundamental;

import android.app.Activity;
import android.net.ConnectivityManager;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class WebActivity extends Activity{

	private Button bt_webButton;
	private EditText et_url;
	private WebView webView;
	private ConnectivityManager connectivityManager;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.webkit);
		
		
		bt_webButton=(Button)findViewById(R.id.bt_tourl);
		et_url=(EditText)findViewById(R.id.et_url);
		webView=(WebView)findViewById(R.id.webViewer);
		
		bt_webButton.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub.
				connectivityManager=(ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
				if(connectivityManager.getActiveNetworkInfo()==null){
					Toast.makeText(WebActivity.this, "Please check your network state!", Toast.LENGTH_SHORT).show();
					return;
				}
				String url=et_url.getText().toString();
				if(url.equals("")){
					Toast.makeText(WebActivity.this, "Please input a url!", Toast.LENGTH_SHORT).show();
				}
				webView.loadUrl(url);
			}
		});
	}
	
}
